﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Handrise.CDCable.Mobile.UI
{
    public class MakeFullScreen
    {
        const int SHFS_SHOWTASKBAR = 0x0001;
        const int SHFS_HIDETASKBAR = 0x0002;
        const int SHFS_SHOWSIPBUTTON = 0x0004;
        const int SHFS_HIDESIPBUTTON = 0x0008;
        const int SHFS_SHOWSTARTICON = 0x0010;
        const int SHFS_HIDESTARTICON = 0x0020;
        const int WS_TABSTOP = 0x00010000;

        const int GWL_STYLE = -16;
        const int GWL_EXSTYLE = -20;

        const int SHIDIM_FLAGS = 0x0001;

        const int SHIDIF_DONEBUTTON = 0x0001;
        const int SHIDIF_SIZEDLG = 0x0002;
        const int SHIDIF_SIZEDLGFULLSCREEN = 0x0004;
        const int SHIDIF_SIPDOWN = 0x0008;
        const int SHIDIF_FULLSCREENNOMENUBAR = 0x0010;
        const int SHIDIF_EMPTYMENU = 0x0020;
        const int SHIDIF_WANTSCROLLBAR = 0x0040;

        public const uint WS_VISIBLE = 0x10000000;
        public const uint WS_EX_TOOLWINDOW = 0x00000080;

        public struct SHINITDLGINFO
        {
            public int dwMask;
            public IntPtr hDlg;
            public int dwFlags;
        } ;


        [DllImport("aygshell.dll", CharSet = CharSet.Auto)]
        public static extern int SHInitDialog(ref SHINITDLGINFO pshidi);


        [DllImport("aygshell.dll", CharSet = CharSet.Auto)]
        public static extern int SHFullScreen(IntPtr hwndRequester, int dwState);

        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
        public static extern int SetForegroundWindow(IntPtr hWnd);

        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
        public static extern int MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, int bRepaint);

        [DllImport("coredll.dll")]
        public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
        [DllImport("coredll.dll")]
        public static extern uint GetWindowLong(IntPtr hWnd, int nIndex);


        const int SM_CXSCREEN = 0;
        const int SM_CYSCREEN = 1;
        [DllImport("coredll.dll")]
        public static extern int GetSystemMetrics(int nIndex);

        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPWStr)]string clsName,
            [MarshalAs(UnmanagedType.LPWStr)]string caption);


        public const int SW_HIDE = 0;
        public const int SW_SHOW = 5;
        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        public static void makeItFullScr(Form form)
        {
            foreach (Control ctrl in form.Controls)
            {
                ctrl.TabStop = false;
            }

            form.Menu = null;

            SetForegroundWindow(form.Handle);
            SHFullScreen(form.Handle, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
            hideTaskBar();
        }

        public static void toRegularScr(Form form)
        {
            SHFullScreen(form.Handle, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);
            showTaskBar();
        }

        public static void hideTaskBar()
        {
            IntPtr hwnd = FindWindow("HHTaskBar", null);
            ShowWindow(hwnd, SW_HIDE);
        }
        public static void showTaskBar()
        {
            IntPtr hwnd = FindWindow("HHTaskBar", null);
            ShowWindow(hwnd, SW_SHOW);
        }
    }
}
